%% Two-Tone DQ driving
% Fig S6

load('./data/FigS6.mat')
filenames={'DQ_rabi_0','DQ_rabi_pi_over_6','DQ_rabi_pi_over_4'};

for hlp_names=1:3
    myfun_rabi_base =@(c,x) c(3)+ c(2)*cos(2*pi*x*c(1)+c(4));
    pbest=cell(3);
    
    figure()
    cc=colormap(piratepal(9,1));
    hold on
    
    for hlp=1:3
        if hlp==2
            myfun_rabi = @(c,x) myfun_rabi_base([c,0],x);
            LB=[3e6,0,-1];
            UB=[5e6,1,1];
            pinit=[4e6,0.5,0.5];
        else
            myfun_rabi = @(c,x) myfun_rabi_base([c,pi],x);
            LB=[3e6,0,-1];
            UB=[5e6,1,1];
            pinit=[4e6,0.25,0.25];
        end
        [pbest{hlp}]=easyfit(x{hlp_names}, y{hlp_names}(hlp,:), pinit, myfun_rabi, LB, UB,'np');
        
        if hlp_names~=3
            plot(x{hlp_names}*1e9,myfun_rabi(pbest{hlp},x{hlp_names}),'LineWidth',1.5,'Color',cc(hlp,:),'HandleVisibility','off')
        end
        
    end
    
    if hlp_names==3
        hlp=2;
        plot(x{hlp_names}*1e9,myfun_rabi_base([pbest{hlp},0],x{hlp_names}),'LineWidth',1.5,'Color',cc(hlp,:),'HandleVisibility','off')
        plot(x{hlp_names}*1e9,myfun_rabi_base([pbest{1}/2+pbest{3}/2,pi],x{hlp_names}),'LineWidth',1.5,'Color',cc(1,:),'HandleVisibility','off')
    end
    
    for hlp=1:3
        plot(x{hlp_names}*1e9,y{hlp_names}(hlp,:),'o','MarkerSize',12,'LineWidth',1.5,'Color',cc(hlp,:))
    end
    
    
    xlabel('Dual-Frequency Rabi Duration (ns)','FontSize',26)
    ylabel('Population','FontSize',26)
    ylim([-0.05,1.05])
    
    set(gca,'FontSize',24)
    
    if hlp_names==3
        legend({'ms=-1','ms=0','ms=+1'},'FontSize',24)
    end
    
%     saveas(gcf,filenames{hlp_names},'epsc')
end

